Easy2Siksha.com
GNDU Question Paper-2021
Bachelor of Computer Application (BCA) 1
st
Sem.
(Batch 2021-24)
INTRODUCTION TO PROGRAMMING-C
Time Allowed: Three Hours Max. Marks: 75
Note: Attempt Five questions in all, selecting at least One question from each section. The
Fifth question may be attempted from any section. All questions carry equal marks.
SECTION-A
1. Write short notes on the following:
(a) Character set
(b) Constant
(c)Symbolic constant
(d) Reserve words
(e)Identifiers.
2. Explain the following types of operators:
(a)Relational
(b)Logical
(c)Arithmetic.
SECTION-B
3. What are the different types of loops available in C? Explain giving suitable examples.
4. Write a program to find ith smallest and jh largest number in a list of n numbers.
Easy2Siksha.com
SECTION-C
5. (a) Define recursion. What are the conditions for implementing recursion?
(b) Write a recursive function to generate ith term of Fibonacci series.
6. Write a program to multiply two matrices and store the result in third matrix.
SECTION-D
7. Define the following:
(a) User defined data type
(b) Structure
(c) Union
(d) Structure and pointers
(e) Self-referencing structure.
8. Define pointer. How pointer to functions is used? Explain giving example.
Easy2Siksha.com
GNDU Answer Paper-2021
Bachelor of Computer Application (BCA) 1
st
Sem.
(Batch 2021-24)
INTRODUCTION TO PROGRAMMING-C
Time Allowed: Three Hours Max. Marks: 75
Note: Attempt Five questions in all, selecting at least One question from each section. The
Fifth question may be attempted from any section. All questions carry equal marks.
SECTION-A
1. Write short notes on the following:
(a) Character set
(b) Constant
(c)Symbolic constant
(d) Reserve words
(e)Identifiers.
Ans: (a) Character Set
Imagine a big box filled with different letters, numbers, and symbols. This box is called the
character set in programming.
󹴡󹴵󹴣󹴤 What is a Character Set?
A character set is the set of characters that a programming language can recognize and use
to form instructions, variables, expressions, and more.
In simpler terms, it includes:
Alphabets (A to Z and a to z)
Digits (0 to 9)
Special characters (like +, -, *, /, &, %, @, etc.)
White spaces (space, tab, newline)
Easy2Siksha.com
Escape sequences (like \n, \t, etc.)
These characters are the raw materials for any program. Just like how letters make up
words in English, characters make up statements in a programming language.
󷃆󹹾󹹿󹺀 Example in C:
In the C language, the standard character set includes:
Type
Characters
Letters
AZ, az
Digits
09
Special characters
+ - * / = % # & ^ ! ~ ; , . < > ? : [] () {}
White spaces
Space, tab, newline
Escape sequences
\n (newline), \t (tab), \ (backslash)
󹳴󹳵󹳶󹳷 Why is Character Set Important?
It is the foundation of writing programs.
It helps in forming tokens, variables, operators, keywords, and more.
Without a character set, the compiler wouldn't know what we are trying to type. It's like
trying to read a book in a language that doesn't have any alphabet!
(b) Constant
Now, Arjun met a wise old man in his village who said, “A constant is like your birthday. It
never changes. It’s fixed in your life.”
󹴡󹴵󹴣󹴤 What is a Constant?
In programming, a constant is a value that does not change throughout the execution of a
program.
Once a constant is defined, its value remains the same, unlike variables which can change.
󼨐󼨑󼨒 Think of It Like This:
If you define:
const int daysInWeek = 7;
This means that daysInWeek will always be 7. You cannot change it to 6 or 8 later in the
program.
󼪺󼪻 Types of Constants:
Easy2Siksha.com
1. Integer Constants
Whole numbers, positive or negative, like 5, -10, 100.
2. Floating-point Constants
Numbers with a decimal point, like 3.14, -0.01, 9.81.
3. Character Constants
Single characters enclosed in single quotes, like 'A', 'z', '9'.
4. String Constants
Sequence of characters enclosed in double quotes, like "Hello", "123", "@!#".
5. Boolean Constants (in some languages)
Represent true or false values, like true, false.
󹳴󹳵󹳶󹳷 Why Use Constants?
To represent fixed values like PI (3.14159), the number of days in a week, etc.
To improve clarity of the program.
To avoid accidental changes to important values.
(c) Symbolic Constant
Now let’s imagine that Arjun writes poems and uses symbols like 󷇱󷇳󷇲 for the sun and 󷇧󷇨󷇩 for
the moon. These symbols represent something else. In programming, a symbolic constant is
a similar idea.
󹴡󹴵󹴣󹴤 What is a Symbolic Constant?
A symbolic constant is a name that symbolizes a constant value. Instead of writing the actual
value again and again, we use a name that stands for it.
󹺊 Example in C:
Using #define:
#define PI 3.14159
#define MAX_LIMIT 100
Now, everywhere you use PI in your program, the compiler will replace it with 3.14159
before the program runs.
So,
area = PI * r * r;
becomes:
area = 3.14159 * r * r;
Easy2Siksha.com
󹳴󹳵󹳶󹳷 Advantages of Symbolic Constants:
1. Easy to read: PI is easier to understand than 3.14159.
2. Easy to update: If you want to change the value, you do it only once in the
definition.
3. Avoids mistakes: Reduces repetition of values, which lowers chances of errors.
Symbolic constants are like nicknames for values!
(d) Reserved Words
As Arjun continued learning, he wrote a sentence in his diary: “I will always return to
programming.” His teacher smiled and said, “Be careful, some words are reserved by the
language itself!”
󹴡󹴵󹴣󹴤 What are Reserved Words?
Reserved words, also known as keywords, are special words that have predefined meanings
in a programming language. You cannot use them as variable names or identifiers.
󺠰󺠱 Example in C:
Some reserved words include:
int, return, if, else, void, for, while, switch, break, continue, const
You cannot do this:
int if = 10; // 󽅂 Invalid
Because if is a reserved word used for decision-making in C.
󹳴󹳵󹳶󹳷 Why are They Important?
They form the syntax rules of a language.
They help the compiler understand what task you are instructing it to do.
They cannot be redefined by the programmer.
󹲹󹲺󹲻󹲼 List of Common Reserved Words in C:
Data Type
Control Structure
Others
int, float
if, else, while
return, break
double, char
for, switch
continue, void
const, void
do, case
sizeof, typedef
These words are protected by the language and are the building blocks of program logic.
Easy2Siksha.com
(e) Identifiers
After spending months learning programming, Arjun finally created his first game. He used
names like score, playerName, and lives in his code. His mentor told him, “These names are
called identifiers they are how your program recognizes its own variables.”
󹴡󹴵󹴣󹴤 What is an Identifier?
An identifier is the name given to various elements of a program such as:
Variables
Functions
Arrays
Structures
User-defined constants
Identifiers help the programmer and the compiler to identify and access the components of
a program.
󽄬󽄭󽄮󽄯󽄰 Example:
int totalMarks;
float average;
char studentName[50];
Here, totalMarks, average, and studentName are identifiers.
󷃆󼽢 Rules for Naming Identifiers:
1. Must begin with a letter (A-Z or a-z) or an underscore _.
2. Can be followed by letters, digits (0-9), or underscores.
3. Cannot be a reserved word.
4. Case-sensitive in languages like C (TotalMarks totalmarks).
󽅂 Invalid Identifiers:
123name (starts with a digit)
float (reserved word)
total marks (space not allowed)
󹳴󹳵󹳶󹳷 Good Practices:
Use meaningful names: salary is better than s.
Use camelCase or underscores for readability: totalMarks or total_marks.
Easy2Siksha.com
Be consistent in naming style throughout the program.
Identifiers are like labels you stick on boxes to know what’s inside. Without them, your
program would be full of confusion.
2. Explain the following types of operators:
(a)Relational
(b)Logical
(c)Arithmetic.
Ans: One pleasant morning in the digital town of Codeville, the programming class at Codeville High
School was buzzing with excitement. Mr. Arjun, the beloved computer science teacher, had
announced that today's class would be different no boring whiteboards, no dry theory. Instead,
he promised a journey into the fascinating world of operators, but with a twist he’d relate
everything to real life.
As the students settled in, Mr. Arjun smiled and said, “Today we’re going to talk about three
special types of operators Relational, Logical, and Arithmetic. These aren’t just symbols
in programming they’re the decision-makers, the calculators, and the truth-tellers of the
digital world.”
And with that, he began.
󼩕󼩖󼩗󼩘󼩙󼩚 1. Arithmetic Operators: The Basic Mathematicians
Real-Life Analogy: Rohan's Sweet Shop
“Let me start with a small story,” said Mr. Arjun.
“In our town, there's a kid named Rohan who runs a small sweet shop. Every day, he
calculates how many laddoos he sells, how many he has left, and how many more he needs
to make.”
These daily tasks involve basic arithmetic operations like addition, subtraction,
multiplication, and division exactly what arithmetic operators do in programming.
Definition:
Arithmetic operators are used to perform basic mathematical operations in programming
just like how we do in real life math.
Operator
Symbol
Example
Addition
+
5 + 3 = 8
Subtract
-
5 - 3 = 2
Easy2Siksha.com
Multiply
*
5 * 3 = 15
Divide
/
6 / 3 = 2.0
Modulus
%
5 % 3 = 2
Increment
++
a++ (if a=2, now a=3)
Decrement
--
a-- (if a=2, now a=1)
Explanation of Each:
Addition (+): Combines two values.
Rohan had 20 laddoos and made 10 more. Total = 20 + 10 = 30.
Subtraction (-): Deducts a value.
Rohan sold 5 laddoos. Remaining = 30 - 5 = 25.
Multiplication (*): Repeated addition.
Each tray holds 4 laddoos. 5 trays = 5 * 4 = 20 laddoos.
Division (/): Splits into equal parts.
He wants to divide 20 laddoos among 4 customers = 20 / 4 = 5 each.
Modulus (%): Gives the remainder.
20 laddoos divided among 6 people: 20 % 6 = 2 (leftovers).
Increment (++) and Decrement (--):
Quick way to increase or decrease a number by 1.
󼩎󼩏󼩐󼩑󼩒󼩓󼩔 2. Relational Operators: The Decision-Makers
After discussing Rohan’s sweet shop, Mr. Arjun turned serious. “Now let’s talk about
decisions. Suppose Rohan needs to decide ‘Do I need to make more sweets? Have I
reached my target?’. These questions are answered using Relational Operators.”
Definition:
Relational operators compare two values and return a boolean result either true or false.
Operator
Symbol
Meaning
Example
Equal to
==
Is equal to
5 == 5 true
Not equal to
!=
Is not equal to
5 != 3 true
Greater than
>
Is greater than
5 > 3 true
Less than
<
Is less than
5 < 3 false
Greater or equal
>=
Greater than or equal
5 >= 5 true
Easy2Siksha.com
Less or equal
<=
Less than or equal
3 <= 5 true
Explanation with Examples:
Equal To (==)
Is Rohan’s daily sale equal to his target of 50 laddoos?
sale == 50
Not Equal To (!=)
Did Rohan sell a different amount than expected?
sale != 50
Greater Than (>)
Did he sell more than 50 laddoos?
sale > 50
Less Than (<)
Did he sell fewer than 50 laddoos?
sale < 50
Greater Than or Equal To (>=)
Did he meet or exceed the goal?
sale >= 50
Less Than or Equal To (<=)
Did he stay within limits?
sale <= 50
These operators help programs make decisions. For example:
if (sale >= target) {
printf("Goal achieved!");
}
󼨐󼨑󼨒 3. Logical Operators: The Thinkers
Mr. Arjun now walked to the board and drew a cartoon brain. “Logical operators,” he said,
“are the brain of programming. They help the program think by combining multiple
conditions.”
Definition:
Logical operators combine two or more relational expressions and return true or false
based on logical relationships.
Operator
Symbol
Meaning
Example
AND
&&
True if both are true
(a > 5) && (b < 10)
Easy2Siksha.com
OR
`
`
NOT
!
Reverses the truth value
!(a > 5)
Explanation with Story
Here’s where another small story helped:
Story: Maya’s Vacation Decision
Maya wants to go on vacation. But she has two conditions:
Her exams must be over.
Her parents must agree.
Now the logical AND operator will help her decide:
if (examsOver && parentsAgree) {
printf("Maya goes on vacation!");
}
If both are true, she goes.
If even one is false, the trip is cancelled.
Now suppose:
She'll go even if just one condition is fulfilled (relaxed rules).
Then she uses the OR operator:
if (examsOver || parentsAgree) {
printf("Vacation possible.");
}
The NOT operator simply reverses the logic:
if (!isRaining) {
printf("Go for a walk.");
}
If it’s not raining, the condition is true.
󼨽󼨾󼨿󼩁󼩀 Let’s Mix Them Together – A Real-World Problem
Easy2Siksha.com
Mr. Arjun smiled and challenged the students:
“Let’s combine everything now.”
Problem: Rohan wants to know:
Has he sold at least 30 laddoos?
Is it not raining (so he can go to the market)?
If both conditions are true, he will go to the market.
if ((laddoosSold >= 30) && (!isRaining)) {
printf("Go to market.");
}
This line uses:
Relational operator (>=)
Logical AND (&&)
Logical NOT (!)
󷃆󹸊󹸋 Summary Table of All Operators
Category
Operator
Description
Arithmetic
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulus (Remainder)
++
Increment by 1
--
Decrement by 1
Relational
==
Equal to
!=
Not equal to
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to
Easy2Siksha.com
Logical
&&
Logical AND (both true)
`
!
Logical NOT (reverse condition)
󹴡󹴵󹴣󹴤 Final Example: A Mini Program
Let’s look at a complete example to bring it all together:
#include <stdio.h>
int main() {
int marks = 85;
int attendance = 90;
int passMarks = 40;
// Use arithmetic
int total = marks + attendance;
// Use relational
if (marks >= passMarks) {
// Use logical
if ((marks > 80) && (attendance > 85)) {
printf("Excellent Student\n");
} else {
printf("Good Student\n");
}
} else {
printf("Needs Improvement\n");
}
return 0;
Easy2Siksha.com
}
󹰎󹰏󹰐󹰑 Why Are These Operators So Important?
Just like a human brain uses comparisons and decisions to act like “Is it hot outside?”,
“Should I wear a jacket?”, “Do I have enough money?” — a program needs the same logic to
work properly.
Arithmetic operators help it calculate.
Relational operators help it compare.
Logical operators help it decide.
Together, they form the backbone of every decision-making process in programming.
󷙎󷙐󷙏 Conclusion: Let Operators Be Your Digital Guide
As the class ended, Mr. Arjun said,
“Just like in real life we add, compare, and decide — our programs must do the same.
Operators are not just symbols they are the thinking tools of code.”
So whether you're helping Rohan run his sweet shop, or you're deciding Maya’s vacation
plans, or just building a simple calculator remember these three types of operators and
how they shape every program.
SECTION-B
3. What are the different types of loops available in C? Explain giving suitable examples.
Ans: 󷇴󷇵󷇶󷇷󷇸󷇹 A New Beginning in Code ville
Once upon a time in the magical land of Code ville, there lived a young programmer named
Aryan. He was smart and curious, always eager to learn new tricks in C programming. One
day, he was facing a problem: he wanted his code to repeat certain tasks like printing
numbers, checking marks of students, or calculating sums without writing the same code
again and again.
Confused, Aryan went to his old mentor, Master Loopananda, a wise C programmer who
told him:
“Aryan, what you seek is called a loop. It’s a tool that helps your program repeat tasks, just
like practicing the same sword move again and again until it's perfect.”
And with a smile, the master began explaining...
Easy2Siksha.com
󷃆󹸃󹸄 What is a Loop in C?
In C programming, a loop is a control structure that allows a block of code to be executed
repeatedly based on a given condition. Instead of writing the same code many times, you
can use a loop to repeat it efficiently.
Think of it like brushing your teeth every day. You don’t tell yourself every morning step-by-
step you just know the routine and repeat it. That’s what a loop does!
󷅑 Types of Loops in C
In C, there are three major types of loops:
1. for loop
2. while loop
3. do-while loop
Let’s learn them one by one with real-life relatable examples.
󷃆󷃊 For Loop: The Planner Loop
Imagine Aryan has to count from 1 to 10.
He knows how many times he wants to count, and he wants to do it in a neat and organized
way.
This is where the for loop shines.
󹺊 Syntax:
for (initialization; condition; increment/decrement) {
// Code to be executed
}
󼪺󼪻 Example:
#include <stdio.h>
int main() {
int i;
for(i = 1; i <= 10; i++) {
printf("%d\n", i);
}
return 0;
Easy2Siksha.com
}
󼨐󼨑󼨒 Explanation:
Initialization: int i = 1 Start counting from 1
Condition: i <= 10 Count till 10
Increment: i++ Go to next number
It’s like saying:
“Start from 1, go until 10, and increase by 1 each time.”
Use for loop when you know in advance how many times you want to repeat something.
󷃆󷃋 While Loop: The Uncertain Adventurer
Now Aryan is on a quest, but he doesn’t know how many steps it will take to reach his goal.
He will keep walking until he finds the treasure.
This is where the while loop is perfect when the number of repetitions is unknown.
󹺊 Syntax:
while (condition) {
// Code to be executed
}
󼪺󼪻 Example:
#include <stdio.h>
int main() {
int i = 1;
while(i <= 5) {
printf("Step %d\n", i);
i++;
}
return 0;
}
󼨐󼨑󼨒 Explanation:
The condition i <= 5 is checked before running the loop.
Easy2Siksha.com
If it’s true, the loop runs.
If it’s false, the loop stops.
Use while loop when you don’t know how many times you’ll need to repeat but you
know the condition to stop.
󷃆󷃌 Do-While Loop: The Optimist’s Loop
Now imagine Aryan wants to try a magic potion at least once even if it turns out to be
bad. He will taste it once anyway, and then decide whether to continue or not.
This is exactly how the do-while loop works.
󹺊 Syntax:
do {
// Code to be executed
} while (condition);
󼪺󼪻 Example:
#include <stdio.h>
int main() {
int i = 1;
do {
printf("Trying potion %d\n", i);
i++;
} while(i <= 3);
return 0;
}
󼨐󼨑󼨒 Explanation:
The loop executes first, then checks the condition.
Even if the condition is false initially, the loop runs at least once.
Use do-while loop when the task must happen at least once before checking the condition.
󹴡󹴵󹴣󹴤 Comparison Table
Easy2Siksha.com
Loop Type
Condition
Check
Executes Minimum
Once?
Best Use Case
for loop
Before loop
No
When you know the number of
repetitions
while loop
Before loop
No
When repetitions depend on some
condition
do-while
loop
After loop
Yes
When you need to run the loop at
least once
󷗭󷗨󷗩󷗪󷗫󷗬 Bonus Story: Aryan and the Infinite Trap
One day, Aryan forgot to increase his counter inside a loop. The result? The loop never
ended!
int i = 1;
while(i <= 5) {
printf("Oops!\n");
// Forgot to write i++
}
This created an infinite loop, and the program kept printing “Oops!” forever. Master
Loopananda laughed and said,
"Never forget to update your loop variable, or you’ll be stuck in the loop of doom!”
󼨐󼨑󼨒 Summary Aryan’s Lessons
By the end of his journey, Aryan learned:
Loops save time and code.
for loop is best when counts are known.
while loop is ideal when the end is uncertain.
do-while loop is good when the task must happen at least once.
Always update your loop variable to avoid infinite loops!
󹰤󹰥󹰦󹰧󹰨 Final Thought
Easy2Siksha.com
Loops in C are like your daily routines. Some are fixed (like brushing your teeth every
morning for loop), some depend on conditions (like watching TV until you get bored
while loop), and some must be done at least once (like trying food before judging do-while
loop).
If you understand their rhythm, you can make your programs smarter, faster, and cleaner
just like Aryan became a master programmer of Codeville.
4. Write a program to find i
th
smallest and j
th
largest number in a list of n numbers.
Ans: The Curious Case of the Number Puzzle
In a small town, there lived a boy named Arjun who loved puzzles more than anything else.
One day, his grandfather gave him a unique challenge:
“Arjun, I have a list of numbers, and I want you to find two things for me — the ith smallest
number and the jth largest number from that list. Can you do that?”
Arjun’s eyes sparkled. He loved these kinds of brain teasers. But his younger sister, Priya,
was curious too.
“Bhaiya, what does ith smallest and jth largest even mean?” she asked.
Arjun smiled and explained, “It’s simple! Imagine we have some numbers written on a
board. If we sort those numbers in ascending order from smallest to biggest then:
The ith smallest means the number that appears at the i-th position in this sorted
list.
The jth largest means we sort the numbers in descending order from biggest to
smallest and pick the number at the j-th position."
Let’s take an example to understand:
Suppose the list is:
[12, 5, 8, 19, 3]
Now if we sort it in ascending order, we get:
[3, 5, 8, 12, 19]
So:
The 1st smallest is 3
The 2nd smallest is 5
The 5th smallest is 19
And if we sort it in descending order, we get:
[19, 12, 8, 5, 3]
So:
Easy2Siksha.com
The 1st largest is 19
The 2nd largest is 12
The 5th largest is 3
Priya smiled, “Oh! That’s like finding the student who came i-th in class if we arrange marks
in increasing or decreasing order!”
Exactly! So now, let’s write a Python program that can do this for any list, and for any values
of i and j that the user provides.
Python Program to Find ith Smallest and jth Largest Number in a List
def find_ith_smallest_and_jth_largest(numbers, i, j):
n = len(numbers)
# Check if i and j are valid
if i < 1 or i > n or j < 1 or j > n:
return "Invalid i or j! They must be within the range of the list length."
# Sort the list in ascending order
sorted_list = sorted(numbers)
ith_smallest = sorted_list[i - 1] # Lists are 0-indexed
jth_largest = sorted_list[-j] # -1 is last, -2 is second last, etc.
return ith_smallest, jth_largest
# Example usage:
numbers = [15, 3, 9, 7, 20, 11]
i = 2
j = 3
ith_smallest, jth_largest = find_ith_smallest_and_jth_largest(numbers, i, j)
Easy2Siksha.com
print(f"The {i}th smallest number is: {ith_smallest}")
print(f"The {j}th largest number is: {jth_largest}")
Let’s Understand the Code Step-by-Step
1. Function Definition:
o find_ith_smallest_and_jth_largest(numbers, i, j) takes three inputs:
numbers: the list of numbers.
i: the position of the smallest number we want.
j: the position of the largest number we want.
2. Checking Valid Inputs:
o We make sure that i and j are not less than 1 and not more than the total
number of elements in the list.
o This step prevents the program from crashing or giving the wrong result.
3. Sorting the List:
o We use Python’s sorted() function, which returns a new list in ascending
order.
o For example, if numbers = [15, 3, 9, 7, 20, 11], the sorted version is [3, 7, 9,
11, 15, 20].
4. Getting the Required Values:
o To find the ith smallest, we use: sorted_list[i - 1]
Because Python lists are 0-indexed. So the 1st smallest is at index 0.
o To find the jth largest, we use negative indexing: sorted_list[-j]
-1 gives the last element, -2 gives second last, etc.
5. Return the Result:
o We return both the ith smallest and jth largest numbers.
Example Run
Let’s say:
numbers = [15, 3, 9, 7, 20, 11]
Easy2Siksha.com
i = 2
j = 3
Sorted list: [3, 7, 9, 11, 15, 20]
2nd smallest → 7
3rd largest → 11
So, the output will be:
The 2th smallest number is: 7
The 3th largest number is: 11
What Makes This Program Special?
󷃆󼽢 Flexible: You can find any ith or jth number just by changing input.
󷃆󼽢 Safe: It checks whether your i and j are within valid limits.
󷃆󼽢 Simple: Sorting does most of the heavy lifting.
Why Sorting Works? (A Quick Peek into Logic)
When we sort the list:
Every element gets a fixed position based on its size.
This helps us easily locate the desired smallest or largest value.
There’s no need to use complex loops or find the minimum multiple times just
one sort, and we’re done!
Another Real-Life Story (Short One)
In a school coding competition, one round had this exact question. While others struggled
with nested loops and complex logic, a girl named Meera simply sorted the list and picked
the required elements.
The judges were impressed not just with her accuracy, but her simplicity.
That’s the beauty of clean logic. The simpler your solution, the more efficient it usually is.
Final Thoughts
This small program teaches us a big lesson:
Easy2Siksha.com
Sometimes, sorting the mess first helps us find what we’re really looking for both in
numbers and in life!
So the next time someone hands you a jumbled list of numbers and asks for the ith smallest
or jth largest smile, sort, and solve!
SECTION-C
5. (a) Define recursion. What are the conditions for implementing recursion?
(b) Write a recursive function to generate ith term of Fibonacci series.
Ans: (a). 󷉃󷉄 A Fresh Start: Grandma's Ladder
Imagine a little boy named Rohan who wanted to climb a ladder to reach a jar of cookies
placed on the top shelf. But the ladder was magical it could only be climbed one step at a
time, and Rohan had to call himself again at each step to keep going higher.
Each time he placed his foot on a new step, he whispered, "Rohan, climb the next step," and
a new Rohan appeared to do just that. This continued until he reached the top. Once he got
the cookies, all the Rohans started disappearing one by one, climbing down as they had
come up. That’s recursion in action!
󷃆󹸊󹸋 What is Recursion?
In programming, recursion is a process where a function calls itself to solve a smaller version
of the original problem. It continues to do this until it reaches a situation where it no longer
needs to call itself this is known as the base condition.
So, just like Rohan climbed each step with the help of a new “version” of himself, in
recursion, the same function solves a part of the problem and calls itself again with a
smaller input until the problem becomes small enough to solve directly.
󹺊 Formal Definition:
Recursion is a programming technique in which a function calls itself directly or indirectly in
order to solve a problem by breaking it down into smaller sub-problems of the same type.
󼨐󼨑󼨒 Real-life Analogy: Russian Dolls
Think of those famous Russian nesting dolls. You open the largest doll, and inside it, there’s
a slightly smaller one and inside that, another, and so on until you reach the smallest
one, which cannot be opened. That smallest doll is like the base condition in recursion, and
Easy2Siksha.com
the process of opening the dolls is like recursive function calls. Once the smallest one is
reached, we start putting them back in this is the process of returning from the recursive
calls.
󷃆󼽢 Conditions for Implementing Recursion:
To make recursion work properly in any programming language, there are two essential
conditions that must be met:
1. Base Case (Termination Condition):
This is the most crucial part of recursion. A base case tells the function when to stop calling
itself.
󹻂 Think of it like a full stop in a sentence without it, the sentence (or function) goes on
forever.
󹻂 Example: In a function to calculate factorial, when n == 1, we stop and return 1.
def factorial(n):
if n == 1: # Base case
return 1
return n * factorial(n - 1)
If we forget the base case, the function will keep calling itself endlessly, causing a stack
overflow the program will crash.
2. Recursive Case (Progress Towards the Base):
The function must call itself with a simpler or smaller version of the problem so that it gets
closer to the base case each time.
󹻂 This ensures that the recursion is not infinite and actually makes progress.
󹻂 In the factorial example, factorial(n - 1) reduces the problem size by 1 each time until n
== 1.
󹲙󹲚󹲛󹲜󹲝󹲞 Example: Sum of Natural Numbers
Let’s take a simple recursive function that calculates the sum of natural numbers up to n:
def sum_natural(n):
Easy2Siksha.com
if n == 1: # Base case
return 1
else:
return n + sum_natural(n - 1) # Recursive case
If you call sum_natural(5), it calculates:
5 + sum_natural(4)
4 + sum_natural(3)
3 + sum_natural(2)
2 + sum_natural(1)
1 (base case reached)
Now, it returns all the values back:
1 2 3 4 5 Total = 15
󼨻󼨼 Key Points to Remember:
Every recursive function must have a base case to stop.
Each recursive call should reduce the problem size and approach the base case.
Recursive solutions are often shorter and more elegant but may use more memory
than loops.
Common problems solved by recursion include:
o Factorial calculation
o Fibonacci series
o Tree traversal
o Tower of Hanoi
o Searching and sorting (like quicksort and mergesort)
󹴡󹴵󹴣󹴤 Conclusion:
Recursion might sound magical or confusing at first like Rohan summoning new versions
of himself but at its heart, it's a simple and powerful tool that helps solve complex
problems by breaking them into smaller, manageable parts.
Easy2Siksha.com
So next time you find yourself opening Russian dolls or climbing a ladder, think of recursion
one step (or one call) at a time, until the job is done!
(b) Write a recursive function to generate ith term of Fibonacci series.
Ans: 󷇴󷇵󷇶󷇷󷇸󷇹 A Different Beginning...
Long ago, in a quiet mountain village, there lived an old shepherd named Arav. Arav didn’t
know much about machines or computers, but he loved numbers. Every day while counting
his sheep, he would hum a strange tune:
1... 1... 2... 3... 5... 8... 13...
One day, a curious boy named Kabir asked him, "Baba, why do you always hum those
numbers?"
With a gentle smile, Arav said, “These are Fibonacci numbers, my boy. Every number is the
sum of the two before it. Just like how we learn from both the past and the present to build
our future.”
This small conversation left a deep impact on Kabir. Years later, Kabir became a computer
science student and remembered the Fibonacci tune from his childhood. When asked to
write a program to find the i-th Fibonacci number, he smiled it was his turn to decode
Baba Arav’s melody.
󹴡󹴵󹴣󹴤 Understanding the Fibonacci Series
Before diving into code, let’s understand what a Fibonacci series is.
The Fibonacci sequence starts like this:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55...
Here’s how it works:
The 0-th term is 0
The 1st term is 1
From the 2nd term onward, each term is the sum of the previous two terms
Mathematically:
F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2) for n ≥ 2
Easy2Siksha.com
Now, let's write a recursive function to find the i-th term of this sequence.
󷃆󹸃󹸄 What is Recursion?
Recursion is when a function calls itself to solve smaller parts of the problem.
In our case:
To find F(i), we’ll use:
o F(i) = F(i - 1) + F(i - 2)
The base cases will be:
o F(0) = 0
o F(1) = 1
If we don't give a base case, the recursion will go on forever like a child asking “Why?” again
and again!
󼨐󼨑󼨒 Recursive Function to Find i-th Fibonacci Term (in Python)
def fibonacci(i):
if i == 0:
return 0
elif i == 1:
return 1
else:
return fibonacci(i - 1) + fibonacci(i - 2)
Let’s walk through an example:
Say we want to find the 5th Fibonacci number.
fibonacci(5)
= fibonacci(4) + fibonacci(3)
= (fibonacci(3) + fibonacci(2)) + (fibonacci(2) + fibonacci(1))
= ((fibonacci(2) + fibonacci(1)) + fibonacci(1)) + ((fibonacci(1) + fibonacci(0)) + 1)
= ...
This will keep breaking down until it hits the base cases fibonacci(1) and fibonacci(0).
Easy2Siksha.com
󼪀󼪃󼪄󼪁󼪅󼪆󼪂󼪇 Why Recursion Feels Like a Story
Recursion is just like storytelling. Imagine a tale told from generation to generation:
The grandfather tells a story that his father told him.
That father tells a story passed from his own father.
Eventually, we reach the first storyteller the base case.
Then the answers (the morals of the story) start flowing backward through the
generations, one by one.
That’s how recursion works. It goes deep down, and once it finds the base case, it climbs
back up solving everything along the way.
󼨻󼨼 A Few Important Points:
Recursive functions are beautiful but not always efficient.
For big values of i, like fibonacci(30) or more, this code becomes slow because it
repeats the same calculation many times.
That’s why memoization or iterative methods are preferred for large inputs. But for
learning and small values, recursion is perfect.
󹹔󹹕󹹖󹹗 Conclusion
Kabir, the student, eventually wrote the recursive function and shared it with his professor.
But deep in his heart, he knew it wasn’t just a piece of code. It was a memory, a melody,
a lesson from Baba Arav that math isn’t just numbers — it’s life, logic, and love combined.
6. Write a program to multiply two matrices and store the result in third matrix.
Ans: 󷇴󷇵󷇶󷇷󷇸󷇹 Beginning Let’s Think Like a Chef
Imagine you are a chef in a large kitchen. Today, you're given an interesting task you have
two different ingredient trays, and your goal is to combine them in such a way that you
create a new dish that is balanced and tasty.
Now, each tray is arranged like a grid (a matrix) rows and columns filled with ingredients.
The trick is: you need to mix ingredients from both trays in a specific mathematical way to
prepare the final dish this dish is our third matrix, the result of matrix multiplication.
Let’s enter the coding kitchen now and understand this step-by-step.
Easy2Siksha.com
󷑏󷑐󷑍󷑎 What is Matrix Multiplication?
In simple terms, matrix multiplication means multiplying rows of the first matrix with
columns of the second matrix, and summing the products.
Let’s say:
Matrix A has dimensions m × n (m rows and n columns)
Matrix B has dimensions n × p (n rows and p columns)
The result matrix, Matrix C, will have dimensions m × p.
󷵻󷵼󷵽󷵾 Condition for Multiplication:
The number of columns in the first matrix must be equal to the number of rows in the
second matrix. Otherwise, matrix multiplication is not possible.
󹰤󹰥󹰦󹰧󹰨 Real-Life Story Students and Subjects
Let’s imagine a classroom with 3 students and 2 subjects.
Matrix A (3×2) stores marks of students in 2 subjects:
A = [
[80, 90],
[70, 85],
[60, 75]
]
Matrix B (2×2) represents the weightage of each subject towards two final assessments:
B = [
[0.4, 0.6],
[0.5, 0.5]
]
When we multiply these matrices, the result matrix (3×2) shows the final scores for each
student in both assessments.
󼨐󼨑󼨒 How It Works The Logic
For each element in the resulting matrix C[i][j], we:
1. Take the i-th row from matrix A
Easy2Siksha.com
2. Take the j-th column from matrix B
3. Multiply each corresponding element and add them
Example:
C[i][j] = A[i][0] * B[0][j] + A[i][1] * B[1][j] + ...
This is done using three nested loops in programming.
󹲙󹲚󹲛󹲜󹲝󹲞 C++ Program to Multiply Two Matrices
Here is a C++ program that multiplies two matrices and stores the result in a third matrix:
#include <iostream>
using namespace std;
int main() {
int A[10][10], B[10][10], C[10][10];
int m, n, p, q;
// Input size of matrices
cout << "Enter rows and columns of Matrix A: ";
cin >> m >> n;
cout << "Enter rows and columns of Matrix B: ";
cin >> p >> q;
if (n != p) {
cout << "Matrix multiplication not possible!";
return 0;
}
// Input Matrix A
cout << "Enter elements of Matrix A:\n";
for (int i = 0; i < m; i++)
Easy2Siksha.com
for (int j = 0; j < n; j++)
cin >> A[i][j];
// Input Matrix B
cout << "Enter elements of Matrix B:\n";
for (int i = 0; i < p; i++)
for (int j = 0; j < q; j++)
cin >> B[i][j];
// Initialize Matrix C with 0
for (int i = 0; i < m; i++)
for (int j = 0; j < q; j++)
C[i][j] = 0;
// Multiply matrices
for (int i = 0; i < m; i++) {
for (int j = 0; j < q; j++) {
for (int k = 0; k < n; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
// Display result
cout << "Resultant Matrix C:\n";
for (int i = 0; i < m; i++) {
for (int j = 0; j < q; j++) {
cout << C[i][j] << " ";
}
Easy2Siksha.com
cout << endl;
}
return 0;
}
󼪺󼪻 Explanation of the Code
First, we take the sizes of matrices A and B from the user.
Then we check the condition for matrix multiplication (columns of A = rows of B).
We use three loops:
o Outer loop for rows of A
o Middle loop for columns of B
o Inner loop for the sum of products (dot product of row and column)
Finally, we display the result matrix C.
󼨽󼨾󼨿󼩁󼩀 Another Simple Example:
A = [ [1, 2], [3, 4] ]
B = [ [5, 6], [7, 8] ]
Then:
C[0][0] = 1×5 + 2×7 = 19
C[0][1] = 1×6 + 2×8 = 22
C[1][0] = 3×5 + 4×7 = 43
C[1][1] = 3×6 + 4×8 = 50
Result:
C = [ [19, 22], [43, 50] ]
󼪺󼪻 Conclusion
Matrix multiplication may sound difficult, but once you understand the pattern like a
recipe in a kitchen or mixing marks with weightage it becomes easy and logical.
Easy2Siksha.com
Programming this is just about carefully applying nested loops and understanding the
position of elements.
SECTION-D
7. Define the following:
(a) User defined data type
(b) Structure
(c) Union
(d) Structure and pointers
(e) Self-referencing structure.
Ans: 󷇴󷇵󷇶󷇷󷇸󷇹 A Journey Through the C Language Village
Once upon a time, in the land of Codeville, there was a small but powerful village called C
Language Village. This village was filled with amazing tools, each with a special role in
managing data. Some tools were simple like int, float, and char, while others were more
advanced and customizable.
One day, five curious students named UserDefined, Structo, Unio, Pointer Singh, and Selfy
decided to explore the depths of the village to understand the power of data in the C
language.
Let’s begin our journey with them to understand:
1. User-defined Data Type
2. Structure
3. Union
4. Structure and Pointers
5. Self-Referencing Structure
󼨐󼨑󼨒 1. What is a User-Defined Data Type?
Imagine you're a chef in a kitchen. You have basic ingredients like salt, sugar, and flour
just like int, char, and float in C. But what if you want to create a special recipe with a
unique mix of ingredients? You’ll have to define it yourself.
Easy2Siksha.com
Similarly, in C, when the basic data types are not enough to represent complex data (like a
student’s name, roll number, and marks), you create your own data type. That is called a
User-Defined Data Type.
󹳴󹳵󹳶󹳷 Definition:
A User-Defined Data Type (UDDT) allows a programmer to create their own data types
based on the existing primitive types. It helps in grouping and organizing different types of
data logically.
󺫦󺫤󺫥󺫧 Types of User-Defined Data Types in C:
struct (Structure)
union
enum (Enumeration)
typedef
󷃆󼽢 Why Use User-Defined Data Types?
To improve readability and reusability of code.
To represent real-world entities easily.
To create custom blueprints for complex objects.
󹲣󼩪󼩫󼩬󼩭󼩲󼩳󼩮󼩯󼩰󼩱 2. What is a Structure?
Let’s meet Structo, a builder in C Language Village. Structo believed in grouping different
things together to form one powerful unit.
For example, to store information about a book, we need:
Book Title → char
Price → float
Pages → int
Instead of storing these separately, we use a structure to group them under one name.
󹳴󹳵󹳶󹳷 Definition:
A structure in C is a user-defined data type that allows grouping variables of different types
under one name.
󼪺󼪻 Syntax:
struct Book {
char title[50];
Easy2Siksha.com
float price;
int pages;
};
󹴷󹴺󹴸󹴹󹴻󹴼󹴽󹴾󹴿󹵀󹵁󹵂 Usage Example:
struct Book b1;
strcpy(b1.title, "C Programming");
b1.price = 299.99;
b1.pages = 500;
Now, the entire book information is stored inside one variable b1.
󷃆󼽢 Advantages of Structure:
Groups different data types together.
Makes handling complex information easier.
Helps create real-world models (like student records, employee info, etc.).
󷃆󹸊󹸋 3. What is a Union?
In a neighboring hut, lived Unio, who was very smart and resource-conscious. He used only
one memory space to store different types of data but only one at a time.
󹳴󹳵󹳶󹳷 Definition:
A union is also a user-defined data type like a structure, but it uses a single memory location
to store different variables. Only one variable can be used at a time.
󼪺󼪻 Syntax:
union Data {
int i;
float f;
char str[20];
};
󹴷󹴺󹴸󹴹󹴻󹴼󹴽󹴾󹴿󹵀󹵁󹵂 Usage Example:
union Data d;
Easy2Siksha.com
d.i = 10; // stores int
d.f = 220.5; // now float value replaces int
strcpy(d.str, "Hi");// now string replaces float
At any time, only one of these can be accessed correctly, because all share the same
memory.
󷃆󼽢 Why Use Unions?
Saves memory when only one variable is needed at a time.
Useful in embedded systems and device drivers where memory is limited.
󼿍󼿎󼿑󼿒󼿏󼿓󼿐󼿔 Structure vs. Union:
Feature
Structure
Union
Memory
Sum of all members
Memory of largest member
Usage
Access all members
Access only one member
Efficiency
Less memory efficient
Highly memory efficient
󹹋󹹌 4. What are Structures and Pointers?
Now comes Pointer Singh, the village’s navigator. He didn’t carry the data himself, but he
always knew where the data lived using addresses.
󹳴󹳵󹳶󹳷 Definition:
A pointer is a variable that stores the address of another variable. When used with
structures, pointers allow us to:
Access members efficiently
Pass structures to functions easily
Dynamically allocate memory
󼪺󼪻 Structure with Pointer Syntax:
struct Student {
char name[50];
int roll;
};
Easy2Siksha.com
struct Student s1 = {"Ravi", 101};
struct Student *ptr = &s1;
󹴷󹴺󹴸󹴹󹴻󹴼󹴽󹴾󹴿󹵀󹵁󹵂 Accessing Structure Members via Pointers:
printf("%s", ptr->name);
printf("%d", ptr->roll);
Use -> (arrow operator) with structure pointers to access members.
󷃆󼽢 Why Use Pointers with Structures?
Allows dynamic memory allocation.
Helps pass structures to functions without copying data.
Used in linked lists, trees, and other data structures.
󷃆󹸃󹸄 5. What is a Self-Referencing Structure?
Here comes the mysterious and powerful Selfy, who was always connected to others like
him. He built a chain of data elements each pointing to another similar structure.
This gave rise to linked data structures like:
Linked Lists
Trees
Stacks and Queues
󹳴󹳵󹳶󹳷 Definition:
A self-referencing structure is a structure that contains a pointer to a structure of its own
type.
󼪺󼪻 Syntax:
struct Node {
int data;
struct Node *next;
};
Here, next is a pointer to another structure of type Node. This helps in creating chains or
links between data items.
󹴷󹴺󹴸󹴹󹴻󹴼󹴽󹴾󹴿󹵀󹵁󹵂 Usage Example: Creating a Simple Node:
struct Node *head;
Easy2Siksha.com
head = (struct Node *)malloc(sizeof(struct Node));
head->data = 5;
head->next = NULL;
Now, we can create another node and link it to head:
struct Node *second = (struct Node *)malloc(sizeof(struct Node));
second->data = 10;
head->next = second;
This chain of nodes is the basis of Linked Lists.
󷃆󼽢 Why Use Self-Referencing Structures?
To build dynamic data structures.
For storing and managing collections of data efficiently.
Makes it easy to insert and delete data without shifting elements.
󽄻󽄼󽄽 A Short Story to Tie It All Together
Let’s revisit the story of our five friends.
One day, a professor gave them a task to design a student database. Here's how each
contributed:
UserDefined said: “Let’s make our own data type using struct.”
Structo built the base structure with name, roll, and marks.
Unio saved memory by using union for temporary data like gender or status.
Pointer Singh helped connect the records dynamically using memory addresses.
Selfy linked them into a chain, allowing the professor to scroll through the records
easily one after another.
The professor was amazed. “You've created the backbone of dynamic and efficient
programming,” he said. The five were honored as Data Warriors of Codeville.
󹲹󹲺󹲻󹲼󹵉󹵊󹵋󹵌󹵍 Final Summary Table
Concept
Meaning
Use Case Example
User-Defined
Data Type
Custom data types created by users using
struct, union, enum
Defining struct Student
Easy2Siksha.com
Structure
Groups variables of different data types
under one name
struct Book { char
name[20]; int p;}
Union
Stores different data types in same
memory location (one at a time)
Efficient memory for
temp variables
Structure +
Pointers
Uses pointers to access/modify structure
data efficiently
struct Student *ptr =
&s1;
Self-Referencing
Struct
Structure pointing to its own type for
linked structures
struct Node *next; in
linked list
󷗭󷗨󷗩󷗪󷗫󷗬 Final Thoughts
Understanding these five concepts is like learning the core tools of a software architect.
These tools help build efficient, flexible, and powerful programs in C whether it's a simple
student record or a complex database.
By grasping the logic behind:
How data is grouped (struct)
How memory is shared (union)
How data is accessed (pointer)
How data is linked (self-referencing)
You are stepping into the world of real-life programming challenges fully equipped and
ready!
8. Define pointer. How pointer to functions is used? Explain giving example.
Ans: 󺠫󺠬󺠭󺠮󺠯 A Doorway to Memory: Understanding Pointers and Pointers to Functions
Imagine you're standing in a huge hotel with thousands of rooms. Each room has a number
written on its door, and inside each room, there's a guest stayinga value.
Now, suppose you're a staff member of this hotel and your job is to deliver messages to the
rooms. But here's the catchyou are not given the guest names directly; you are only given
the room number.
So, you don't deal with the guest (value) directly, but with the room number (address)
where the guest is staying.
This is exactly how a pointer works in programming. It does not store a value directly but
stores the address of the memory location where the value is kept.
Easy2Siksha.com
󹳴󹳵󹳶󹳷 What is a Pointer?
In simple terms:
A pointer is a variable that stores the memory address of another variable.
If you have a variable like:
int num = 10;
Then, you can create a pointer that stores the address of num:
int *ptr = &num;
Here:
int *ptr → Declares a pointer to an integer.
&num This is the "address of" operator. It gives the memory location of num.
*ptr This is the "dereference" operator. It gives you the value stored at the
address contained in ptr.
So,
ptr stores the address of num.
*ptr gives you the value of num.
󼨐󼨑󼨒 Real-Life Analogy (Short Story)
Let’s say there's a boy named Aman who wants to read his favorite book. But the book is in
a locker. Aman does not know what the book sayshe only has the key to the locker.
Similarly, in C programming, a variable is like the book, the memory is like the locker, and
the pointer is the key that opens the locker to access the book.
Without the key (pointer), you can't read the book (access the value).
󷗭󷗨󷗩󷗪󷗫󷗬 Why Use Pointers?
Pointers may seem a bit confusing at first, but they are extremely powerful. They allow:
Dynamic memory allocation (allocating memory during runtime)
Passing arguments by reference
Efficient array handling
Creating complex data structures (like linked lists, trees)
And most interestingly Function pointers
Easy2Siksha.com
󼩎󼩏󼩐󼩑󼩒󼩓󼩔 What is a Pointer to a Function?
Just like you can store the address of a variable in a pointer, you can also store the address
of a function in a pointer.
This is called a pointer to a function.
A pointer to a function is a pointer that points to the starting address of a function in
memory.
Why would we want to store a function's address? Think of this:
What if we want to call different functions depending on the situation, but we don’t know
which one until runtime?
This is where function pointers shine.
󼨽󼨾󼨿󼩁󼩀 Syntax of Function Pointers
Let’s start with a simple function:
int add(int a, int b) {
return a + b;
}
To create a function pointer for this:
int (*funcPtr)(int, int);
This means:
funcPtr is a pointer to a function that takes two integers and returns an integer.
Assign the address of the function:
funcPtr = &add; // Or simply funcPtr = add;
Now call the function through the pointer:
int result = funcPtr(5, 3); // Same as add(5, 3)
So, this will return 8.
󼪈󼪊󼪉 Story to Understand Function Pointers
Let’s say you’re running a restaurant. Every customer can choose between three types of
food: Burger, Pizza, or Pasta. Depending on the customer’s choice, the chef prepares a
different dish.
Easy2Siksha.com
Now, instead of writing if-else statements every time, you assign a pointer to the dish
preparation function. This way, your code becomes dynamic and flexible.
󹲙󹲚󹲛󹲜󹲝󹲞 Example Code: Function Pointer in Action
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int subtract(int a, int b) {
return a - b;
}
int multiply(int a, int b) {
return a * b;
}
int divide(int a, int b) {
return b != 0 ? a / b : 0;
}
int main() {
// Declare a function pointer
int (*operation)(int, int);
// Assign function to pointer based on user choice
int choice, a = 20, b = 10;
printf("Choose operation:\n1. Add\n2. Subtract\n3. Multiply\n4. Divide\n");
Easy2Siksha.com
scanf("%d", &choice);
switch (choice) {
case 1: operation = add; break;
case 2: operation = subtract; break;
case 3: operation = multiply; break;
case 4: operation = divide; break;
default: printf("Invalid choice\n"); return 0;
}
int result = operation(a, b);
printf("Result: %d\n", result);
return 0;
}
󹸯󹸭󹸮 Breaking It Down
In the above example:
We declare a function pointer: int (*operation)(int, int);
We assign the function to the pointer based on user input.
Finally, we call the function using operation(a, b);
This is a powerful technique that helps make the code more modular and reusable.
󹴷󹴺󹴸󹴹󹴻󹴼󹴽󹴾󹴿󹵀󹵁󹵂 Key Advantages of Function Pointers
They help in implementing callback functions.
Useful in event-driven programming (e.g., GUI, system software).
Helps in designing plugins or interfaces.
Helps in building tables of functions for example, jump tables in compilers.
Easy2Siksha.com
󷙎󷙐󷙏 Conclusion
Pointers are like magical keys in programming that allow us to access memory directly. And
function pointers? They are even more powerfulthey let us decide at runtime which
function should be executed.
To master C or C++, you must become comfortable with pointers. They unlock a whole new
level of control, flexibility, and performance.
So, the next time you see *, don’t panic. Remember Aman and his locker key, and think of
function pointers as assigning chefs dynamically in a restaurant kitchen. It’s all about
controlling access, flexibility, and saving effort.
“This paper has been carefully prepared for educational purposes. If you notice any mistakes or
have suggestions, feel free to share your feedback.”